<?php

class AdAction extends CommonAction{
     private  $table_name = "Ad";
	  function index(){
	  	
	  	$this->list =M($this->table_name)->select();
	  	$this->display();
	  	 
	  	
	  }

	  
	  //删除图片
	  function del(){
	  	
	  	 M($this->table_name)->where("id=".$_GET['id'])->delete();
	  	 $this->success("删除成功！");  
	  }
	  
	  
	  function add(){
	  	import('ORG.Net.UploadFile');

	  	$path=date("Ym").'/';

	  	$upload = new UploadFile();// 实例化上传类

	  	$upload->maxSize  = 3145728 ;// 设置附件上传大小

	  	$upload->allowExts  = array('jpg', 'gif', 'png', 'jpeg','rar','zip');// 设置附件上传类型

	  	$upload->savePath =  './Data/photo/'.$path;// 设置附件上传目录
	  	if(!file_exists("./Data/photo/".$path)){
	  		mkdir("./Data/photo/".$path);
	  	}
         
	  	if(!$upload->upload()) {
	  		// 上传错误提示错误信息
	  		$this->error($upload->getErrorMsg());
	  	}else{
	  		$info = $upload->getUploadFileInfo(); //获取上传结果信息

	  		$photopath= str_replace(".","",$info[0]['savepath']);

	  		$s=$photopath.$info[0]['savename'];
            $data['title'] = $_POST['title'];
            $data['photourl'] = $s; 
            
	  		if(M('Ad')->add($data)){
	  			
	  			$this->success("操作成功！");
	  		}

	  	}

	  	
	  }
	
	
}
?>